import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import s_get from '@dfeidao/atom-web/storage/get';
import hide from '@dfeidao/atom-web/ui/hide';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';

export default async function a003(fd: IFeidaoAiBrowserComponent) {
	const name = fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="name"]').value;
	const productid = await s_get('productid');
	const obj = {
		name,
		productid
	};
	if (!name) {
		error("请完善权限组名称");
		return;
	} else {
		const res = await nodejs('functional-permissions/zj-000003/s001', obj);
		if (res === 'success') {
			success("保存成功");
			fire('zj-000001', 'ec-001');
		} else if (res === 'fail') {
			error("保存失败");
			return;
		} else {
			error("权限组名称重复");
			return;
		}
		hide(fd.data.node);
		fd.data.node.querySelector<HTMLInputElement>('[data-feidao-id="name"]').value = '';
	}
}

